//
//  CAMediaTiming_DemoVC.swift
//  APSwift
//
//  Created by jianbo.pei on 2022/5/8.
//

import UIKit

class CAMediaTiming_DemoVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        fillModeDemo()
    }
    
    private func fillModeDemo() {
        let colorLayer = CALayer()
        colorLayer.position = self.view.layer.position
        colorLayer.bounds = CGRect(x: 0, y: 0, width: 50, height: 50)
        colorLayer.backgroundColor = UIColor.orange.cgColor
        self.view.layer.addSublayer(colorLayer)
        
        let basicAnimation = CABasicAnimation(keyPath: "bounds")
        basicAnimation.fromValue = CGRect(x: 0, y: 0, width: 200, height: 200)
        basicAnimation.toValue = CGRect(x: 0, y: 0, width: 400, height: 400)
        basicAnimation.beginTime = 3
        basicAnimation.duration = 4
        basicAnimation.fillMode = .removed
//        basicAnimation.fillMode = .forwards
//        basicAnimation.fillMode = .backwards
//        basicAnimation.fillMode = .both
        
        let animationGroup = CAAnimationGroup()
        animationGroup.duration = 10
        animationGroup.animations = [basicAnimation]
        colorLayer.add(animationGroup, forKey: nil)
    }



}
